package com.ty.user.starter.config;

import com.ty.user.starter.properties.UserMgtProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author minku
 * @date 2021/10/21
 */
@Configuration
public class UserMgtWebMvcConfigurer implements WebMvcConfigurer {

    private final UserMgtProperties userMgtProperties;

    private static final String FILE = "file:";

    @Autowired
    public UserMgtWebMvcConfigurer(UserMgtProperties userMgtProperties) {
        this.userMgtProperties = userMgtProperties;
    }

    /**
     * 配置静态目录映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/user/photo/**").addResourceLocations(FILE + userMgtProperties.getPhotoPath());
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
